//https://leetcode.cn/problems/kth-largest-element-in-a-stream/

class KthLargest {
    priority_queue<int, vector<int>, greater<int>> pq;
    int _k;
public:
    KthLargest(int k, vector<int>& nums) {
        _k = k;
        for (auto x : nums)
        {
            pq.push(x);
            if (pq.size() > _k)
            {
                pq.pop();
            }
        }

    }

    int add(int val) {
        pq.push(val);
        if (pq.size() > _k)
        {
            pq.pop();
        }

        return pq.top();

    }
};